(*
  Copyright (c) 2009 Barry Schwartz

  Permission is hereby granted, free of charge, to any person
  obtaining a copy of this software and associated documentation
  files (the "Software"), to deal in the Software without
  restriction, including without limitation the rights to use,
  copy, modify, merge, publish, distribute, sublicense, and/or sell
  copies of the Software, and to permit persons to whom the
  Software is furnished to do so, subject to the following
  conditions:

  The above copyright notice and this permission notice shall be
  included in all copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  OTHER DEALINGS IN THE SOFTWARE.
*)

open XNum
open UTypes
open SymbolTable
  
type assoc = | Left | NonA | Right

type token_class =
  | EOF
  | LID of symbol
  | UID of symbol
  | NUMBER of num
  | CHARACTER of int
  | STRING of int list
  | BINOP of symbol * int * assoc
  | PREOP of symbol
  | POSTOP of symbol
  | PARENOPEN
  | PARENCLOSE
  | BRACKETOPEN
  | BRACKETCLOSE
  | BRACEOPEN
  | BRACECLOSE
  | APOSTROPHE
  | QUOTE
  | COMMA
  | COLON
  | SEMICOLON
  | UNDERSCORE
  | EQUAL
  | COLON_EQUAL
  | BAR
  | AMPERSAND
  | PERIOD
  | DO
  | IF
  | THEN
  | ELSE
  | ELSEIF
  | END
  | FORCE
  | BEGIN
  | MATCH
  | WITH
  | LOCAL
  | WHERE
  | INFIX of assoc
  | PREFIX
  | POSTFIX

type lexer

val initial_symbol_table : unit -> (uc_string, token_class) Hashtbl.t
  
val make_lexer :
  (uc_string, token_class) Hashtbl.t -> UCStream.istream -> lexer
  
val set_stream : lexer -> UCStream.istream -> unit
  
val read_token : lexer -> token_class
  
val restore_token : lexer -> token_class -> unit
  
val add_bin_op : lexer -> int -> assoc -> symbol -> unit
  
val add_pre_op : lexer -> symbol -> unit
  
val add_post_op : lexer -> symbol -> unit
  
val token_to_string : token_class -> uc_string
  
val syntax_error : lexer -> string -> 'a
  
val syntax_error_uc : lexer -> uc_string -> 'a
  

